home *** CD-ROM | disk | FTP | other *** search
- Path: uni-erlangen.de!winx03!sunshine!schoof
- From: schoof@informatik.uni-wuerzburg.de (Jochen Schoof)
- Newsgroups: comp.lang.c
- Subject: Re: What's your compiler's answer?
- Date: 8 Feb 1996 11:09:00 GMT
- Organization: University of Wuerzburg, Germany
- Message-ID: <4fclkc$shq@winx03.informatik.uni-wuerzburg.de>
- References: <1996Feb7.140945.28351@cs.rit.edu>
- NNTP-Posting-Host: wi2x01.informatik.uni-wuerzburg.de
- X-Newsreader: TIN [version 1.2 PL2]
-
- Kenneth A Reek (kar@cs.rit.edu) wrote:
- : In preparing some materials for a course, I wrote the following
- : program to illustrate that the order of expression evaluation is not
- : determined completely by the precedence of the operators involved. I
- : ran it on every compiler I could find and, not surprisingly, got lots of
- : different answers.
-
- Let me tell you your example is not a good proof for this, because
- it may produce ANY result. Changing a variable more than once between
- sequence points (as you do with i) invokes undefined behaviour.
-
- : I'd like to get results from this program for as many different
- : compilers as I can to drive home the point that expressions of this
- : sort must be avoided. If you have access to a C compiler OTHER THAN
-
- They must be avoided, but the reason is not the undetermined order of
- evaluation, but the fact that a compiler is free to do literally
- anything after evaluating this expression.
-
- : THE ONES LISTED BELOW, I'd be grateful if you could run this program
- : and send me the results. Please include the operating system you are
- : using (if appropriate to the identification of the compiler) and the
- : compiler version number if it has one.
-
- What would you do if I told you that the program compiled with Joscho C
- made my monitor implode? At least this would not keep the compiler from
- being ANSI-compliant :-)
-
- : Here's the program (hold on to your hats):
- :
- : int main(){
- : int i = 10;
- :
- : i = i-- - --i * ( i = -3 ) * i++ + ++i;
- : printf( "i = %d\n", i );
- : return 0;
- : }
- :
- : Results found to date:
- :
- : 21 Borland C/C++ 4.0, Turbo C++ 4.5
- : -86 Sun 3/50 cc
- : -85 Sun Sparc cc, SunOS 4.1.4 (a K&R compiler)
- : 4 Sun Sparc acc, SunOS 4.1.4 (an ANSI compiler)
- : 36 DEC VAX/VMS
- : 21 Silicon Graphics Indy, IRIX 5.3
- : -63 gcc 2.6.3
-
- monitor imploded - Joscho C on a HAL 9000 ;-)
-
- Greetings
-
- - Jochen
-
- --
- --------------------------------------------------------------------------
- Jochen Schoof mailto:schoof@informatik.uni-wuerzburg.de
- Lehrstuhl fuer Informatik II +-------------------------------------------
- Universitaet Wuerzburg | You are just reading a .sig-light:
- D-97074 Wuerzburg (Germany) | It is free of fat, sugar and cholesterol!
- ------------------------------+-------------------------------------------
- WWW-Homepage: http://www.informatik.uni-wuerzburg.de/staff/joscho
- --------------------------------------------------------------------------
-